package com.retail.system.controller;

import com.retail.core.common.AbstractCommonController;
import com.retail.core.entity.ParamReq;
import com.retail.core.entity.result.PageResult;
import com.retail.core.entity.result.Result;
import com.retail.global.annon.TraceLog;
import com.retail.global.security.LoginUserUtil;
import com.retail.system.entity.request.IconRequest;
import com.retail.system.entity.vo.IconVo;
import com.retail.system.service.IconService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @author Administrator
*/
@Api(tags = "图标请求API")
@RestController
@RequestMapping("/icon")
public class IconController extends AbstractCommonController<IconService, IconRequest, IconVo>{

    private final IconService iconService;

    public IconController(IconService iconService) {
        this.iconService = iconService;
    }

    @ApiOperation("详情")
    @TraceLog()
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(iconService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("生成图标")
    public Result<Integer> save(@RequestBody IconRequest iconRequest) {
        return super.save(iconService, iconRequest);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新图标")
    public Result<Integer> update(@RequestBody IconRequest iconRequest) {
        return super.update(iconService, iconRequest);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("数据表")
    public Result<List<IconVo>> listPage(@RequestBody ParamReq<IconRequest> req)  {
        return super.listPage(iconService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("数据表-统计")
    public Result<Integer> countPage(@RequestBody ParamReq<IconRequest> req)  {
        return super.countPage(iconService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("数据表-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<IconRequest> req)  {
        return super.page(iconService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除生成代码")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(iconService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除生成代码")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(@PathVariable("ids") List<Long> ids) {
        return super.batchDelete(iconService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }
}
